#include "qlist.h"

table_t *qlist = NULL;


static int add_to_qlist(void ** record, unsigned char * key, void * val)
{
	request_info* pinfo = (request_info*)*record;
	
	if (!pinfo)
	{
		*record = val;
		return 0;
	}

	return -1;
}


inline table_t* get_qlist()
{
	if (!qlist)
	{
		qlist = create_table(1024);
		qlist->add_value = add_to_qlist;
	}
	return qlist;
}



int insert_to_qlist(request_info* pinfo)
{
	return insert_to_table(get_qlist(), pinfo->lowerdomain.label[0], pinfo->lowerdomain.label_len[0], (void*)pinfo, 0);
}

request_info* find_from_qlist(unsigned char * key)
{
	table_t* qlist = get_qlist();
	request_info* record = (request_info*)find_from_table(qlist, key, strlen(key) + 1, 0);
	return record;
}
void delete_from_qlist(unsigned char *key, unsigned int key_len, hash_t hash)
{
	request_info *record = (request_info*)take_from_table(get_qlist(), key, key_len, hash);
	free(record);
}